package org.jbit.news.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jbit.news.biz.CommentBiz;
import org.jbit.news.biz.NewsBiz;
import org.jbit.news.biz.TopicBiz;
import org.jbit.news.biz.impl.CommentBizImpl;
import org.jbit.news.biz.impl.NewsBizImpl;
import org.jbit.news.biz.impl.TopicBizImpl;
import org.jbit.news.entity.Comment;
import org.jbit.news.entity.News;

public class NewsReadServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
      	response.setCharacterEncoding("utf-8");
      	String nid=request.getParameter("nid");
      	HttpSession session =request.getSession();
      	NewsBiz nb=new NewsBizImpl();
      	List<News> list=nb.getNewsByNid(Integer.parseInt(nid));
      	String ntitle=null;
      	String ncdate=null;
      	String ncontent=null;
      	String ntid=null;
      	String nauthor=null;
      	for(News news:list){
      		ntitle=news.getNtitle();
      		ncdate=news.getNcreatedate();
      		ncontent=news.getNcontent();
      		ntid=news.getNtid();
      		nauthor=news.getNauthor();
      	}
      	
    	request.setAttribute("nid", nid);
    	request.setAttribute("ntitle", ntitle);
    	request.setAttribute("ncdate", ncdate);
    	request.setAttribute("ncontent", ncontent);
    	session.setAttribute("ntid", ntid);
    	request.setAttribute("nauthor", nauthor);
    	
      	
      	CommentBiz commentBiz=new CommentBizImpl();
      	List<Comment> commentslist=commentBiz.getComments(nid);
      	session.setAttribute("commentslist", commentslist);
		
	
	
		
		//国内的侧边栏
		  List<News> newsChina=nb.getNewsByTopicTid(1);
		  session.setAttribute("newChinaList", newsChina);
		  //国际的侧边栏
		  List<News> newsinv=nb.getNewsByTopicTid(2);
		  session.setAttribute("newsinvList", newsinv);
		  //娱乐的侧边栏
		  List<News> newsYule=nb.getNewsByTopicTid(5);
		  session.setAttribute("newYuleList", newsYule);
		  //获取所有的主题
		request.getRequestDispatcher("../newspages/news_read.jsp").forward(request, response);
		
	}
	
}
